﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Web7.Mvc.ViewModels;
using Web7.Mvc.ActionResults;

namespace Web7.Mvc.ActionFilters.Exception
{
    public class ErrorExceptionFilter : IExceptionFilter
    {
        #region IExceptionFilter Members

        public void OnException(ExceptionContext filterContext)
        {
            Web7ViewModel model = filterContext.Controller.ViewData.Model as Web7ViewModel;

            filterContext.Controller.ViewData.Model = new ExceptionWeb7ViewModel(model, filterContext.Exception);

            /*
#if DEBUG
            filterContext.HttpContext.AddError(filterContext.Exception);
#endif
            */
            filterContext.ExceptionHandled = true;

            filterContext.Result = new ErrorResult();
        }

        #endregion
    }
}
